package com.dingshi.security.api;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.dingshi.security.config.HttpClientConfig;
import com.dingshi.security.net.HttpResult;
import com.dingshi.security.net.HttpResultJson;
import com.dingshi.security.net.NetService;

public class NightApi extends BaseApi {

	protected static final String TAG = "NightApi";

	public NightApi(Context context) {
		super(context);
	}

	/**
	 * 	部门编号 n
		地区编号 a
		保安编号 s
		确认情况 c
		日志编号 d
	 * @param requestCode
	 * @param number
	 * @param context
	 */
	public void reportNightShift(final int requestCode, final Context context,final String depNum,final String areaNum,final String guardNum,
			final String isNormal,final String diaryNum){
	
		
		
		new AsyncTask<Object, Integer, ApiResult<Object>>() {
			@Override
			protected ApiResult<Object> doInBackground(Object... strs) {
				JSONObject obj = new JSONObject();
				try {
					obj.put("n", depNum);
					obj.put("a", areaNum);
					obj.put("s", guardNum);
					obj.put("c", isNormal);
					obj.put("d", diaryNum!=null?diaryNum:"");
				} catch (JSONException e2) {
					e2.printStackTrace();
				}
				Log.e(TAG, "request params "+obj.toString());
				ApiResult<Object> apiResult = new ApiResult<Object>();
				apiResult.setResultCode(ApiResult.RESULT_FAIL);
				HttpResultJson result = NetService.getWebServices(obj.toString(),context,HttpClientConfig.NIGHT_SHIFT);
				if (result.getResultCode() == HttpResult.RESULT_OK) {
					apiResult.setResultCode(ApiResult.RESULT_OK);
					JSONObject json = result.getJson();
					apiResult.setJsonEntity(json);

				} else {
					apiResult.setFailCode(result.getFailCode());
					apiResult.setFailMessage(result.getFailMessage());
				}
				return apiResult;
			}

			@Override
			protected void onPostExecute(ApiResult<Object> apiResult) {
				if (returnResultListener == null) {
					return;
				}
				if (apiResult.getResultCode() == ApiResult.RESULT_OK) {
					returnResultListener.onReturnSucceedResult(requestCode,
							apiResult);
				} else {
					returnResultListener.onReturnFailResult(requestCode,
							apiResult);
				}
			}

			@Override
			protected void onPreExecute() {
				if (returnResultListener == null) {
					return;
				}
					returnResultListener.onReturnLoading(requestCode);
				super.onPreExecute();
			}
			
			
			
		}.execute("");
	}
}
